var WxParse = require('../wxParse/wxParse.js');
export function getModelInfo(page) {
  wx.request({
    url: 'https://open.oppomobile.com/agentplatform/app_api/model_info', // 替换为实际接口地址
    method: 'GET',
    header: {
      'Authorization': 'Bearer Rfl0IQuZR9vBT75i', // 替换为实际的授权令牌
    },
    success: (res) => {
      if (res.statusCode === 200 && res.data.code === '0000') {
        const modelInfo = res.data.data;

        // 获取当前时间戳
        const timestamp = Math.floor(Date.now() / 1000);
        console.log('timestamp',timestamp)
        WxParse.wxParse('openingRemarks', 'md', modelInfo.opening_remarks, page, 5);
        page.setData({
          modelInfo: modelInfo,
          messages: [{
              role: 'ai',
              content: modelInfo.opening_remarks,
              displayContent: page.data.openingRemarks.nodes,
              isImage: false,
              createdAt: timestamp // 添加时间戳
            },
            ...modelInfo.suggestions.map(suggestion => ({
              role: 'suggestion',
              content: suggestion,
              isImage: false,
              createdAt: timestamp
            }))
          ],
        });
        console.log('Model Info:', modelInfo);
      } else {
        wx.showToast({
          title: '获取模型信息失败',
          icon: 'none',
        });
      }
    },
    fail: (err) => {
      wx.showToast({
        title: '请求失败',
        icon: 'none',
      });
      console.error('Request failed:', err);
    },
  });
}
